package coffee;

import bean.Bean;
import java.util.HashMap;
import java.util.Map;

public class Coffee {

    private static final int SIZE = 0;
    private static final int SHOT = 1;
    private static final int DAIRY = 2;
    private static final int COLD = 3;
    private static final int TAKEOUT = 4;
    private static final int BEAN = 5;

    private String size = "tall"; // tall, grande
    private String dairy = "semi";

    private int shot = 2;
    private Bean bean;

    private boolean isCold = false;
    private boolean isTakeout = false;
    protected static int price = 20;

    private static Map<String, Integer> priceMap = new HashMap<>();

    static {
        // size
        priceMap.put("short", -2);
        priceMap.put("tall", 0);
        priceMap.put("grande", 5);
        priceMap.put("venti", 8);

        // dairy
        priceMap.put("coconut", 2);
        priceMap.put("oat", 2);
        priceMap.put("almond", 2);
        priceMap.put("soy", 0);

        priceMap.put("semi", 0);
        priceMap.put("whole", 0);
        priceMap.put("skim", 0);

        // cold / hot
        priceMap.put("cold", 1);
        priceMap.put("hot", 0);

        // takeout / stay
        priceMap.put("takeout", 1);
        priceMap.put("stay", 0);
    }

    public void calculatePrice(String input) {
        price += priceMap.get(input);
    }

    private void setBean(String bean) {
        // this.bean = new Bean(bean);
    }

    // public void initPrice() {
    // this.price = 20;
    // }

    // input format: size|shot|dairy|cold|takeout|bean
    public Coffee(String input) {
        String[] properties = input.split("\\|");
        for (String x : properties)
            System.out.println(x);

        // initPrice();
        this.size = properties[SIZE];
        this.shot = Integer.parseInt(properties[SHOT]);
        this.dairy = properties[DAIRY];
        this.isCold = properties[COLD] == "cold";
        this.isTakeout = properties[TAKEOUT] == "takeout";
        setBean(properties[BEAN]);

        for (int i = SIZE; i < BEAN; i++) {
            if (i == SHOT) {
                price += (this.shot - 2) * 3;
            } else {
                price += priceMap.get(properties[i]);
            }
        }
    }

    public float getPrice() {
        return price;
    }
}
